package com.client.security;

/**
 * @author fengJiaBin
 * @version 1.0
 * @description: TODO
 * @date 2021/5/12 9:54
 */

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;

@Configuration
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.exceptionHandling().and()
                // 由于使用的是JWT，我们这里不需要csrf
                .csrf().disable()
                //跨域允许
                .cors().and()
                // 基于token，所以不需要session
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .authorizeRequests()
                //不对springboot-admin监控的请求进行权限校验
                .antMatchers("/actuator/**").permitAll()
                //不对springboot-admin监控的实例信息请求进行权限校验
                .antMatchers("/instances/**").permitAll()
                //不对springboot-admin监控的实例信息请求进行权限校
                .antMatchers("/heath/**").permitAll()
                .antMatchers("/**/**").permitAll();
    }
}
